﻿using Newtonsoft.Json;

namespace Keede.RabbitMQ.EasyClient
{
    public class Publisher : BaseClient, IPublisher
    {
        public Publisher(Authorization auth, string exchange, string msgAssembly, bool isLogDetail = false) :
            base(auth, exchange, msgAssembly, isLogDetail)
        {
        }

        /// <summary>
        /// publish message
        /// </summary>
        /// <typeparam name="T">message type</typeparam>
        /// <param name="obj">message object</param>
        public void Publish(BaseMsg obj)
        {
            string routingKey = obj.GetType().Name;
            this._mqClient.Publish(JsonConvert.SerializeObject(obj), this._exchange, routingKey);
        }
    }
}
